<?php
/**
 * Created by PhpStorm.
 * User: gzq
 * Date: 13-12-13
 * Time: 下午10:40
 */

class User
{
    private $db;
    public $state = 0;
    public $a = '';

    //构造函数
    public function __construct()
    {
        require_once("DB.php");
        $this->db = new DB();
    }

    public function Action($a, $d)
    {
        $this->a = $a;
        switch ($a) {
            case 'login':
                $item = $this->db->get_one("SELECT * FROM user Where name='".$d->name."' and pwd ='".$d->pwd."'",MYSQL_NUM);
                if (empty($item)) {
                    $this->state = -1;
                } else {
                    $this->state = 1;
                }
                break;
            case 'register':
                $insert = array('name'=>$d->name, 'pwd'=>$d->pwd);
                if($this->db->insert("user",$insert)){
                    $this->state = 1;
                }else{
                    $this->state = -1;
                }
                break;
        }
        return $this;
    }
} 